package com.wyc.controller;

import com.wyc.pojo.Allusers;
import com.wyc.pojo.MoveOut;
import com.wyc.service.MoveOutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.Timestamp;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName MoveOutController
 * @Author 王韫琛
 * @Date 2021/2/1 19:01
 * @Version 1.0
 */
@Controller
public class MoveOutController {
    @Autowired
    MoveOutService moveOutService;
    //普通提交申请信息
    @RequestMapping("/submitInformation")
    @ResponseBody
    public String submitInformation(MoveOut moveOut){
        moveOut.setAddtime(Timestamp.from(Instant.now()).toString());
        Map<String, Object> map = new HashMap<>();
        if (moveOutService.submitInformation(moveOut) >0){
            map.put("success",true);
            map.put("message","添加成功");
        }else {
            map.put("success",false);
            map.put("message","修改失败");
        }
        return cn.hutool.json.JSONUtil.toJsonStr(map);
    }
    //分页显示查询的信息返回页面
    @RequestMapping("/superAdminFind")
    @ResponseBody
    public String superAdminFindPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                     @RequestParam(defaultValue = "10") Integer pageSize){
        Map<String,Object> map = new HashMap<>();
        List<MoveOut> pageInfo = moveOutService.superAdminFind(pageNum, pageSize);
        map.put("code",0);
        map.put("msg","");
        map.put("count",moveOutService.getTotal());
        map.put("data",pageInfo);//数据列表
        return cn.hutool.json.JSONUtil.toJsonStr(map);
    }
    //根据身份证查询迁出用户信息
    @RequestMapping("/moSelectByIdentityCard")
    @ResponseBody
    public String selectByIdentityCard(String identity_card){
        MoveOut moveOut = moveOutService.selectByIdentityCard(identity_card);
        Map<String,Object> map = new HashMap<>();
        List<MoveOut> list = new ArrayList<>();
        list.add(moveOut);
        map.put("code",0);
        map.put("msg","");
        map.put("count",1);//总数量
        map.put("data",list);//数据列表
        return cn.hutool.json.JSONUtil.toJsonStr(map);
    }

}
